package com.yuan.spring.mvc;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.async.WebAsyncTask;
import org.springframework.web.servlet.ModelAndView;

import java.util.concurrent.Callable;

/**
 * Created by 袁恩光 on 2018/2/2.
 */
@RestController
public class AsyncController {


    @RequestMapping(value="async")
    public WebAsyncTask<String> longTimeTask(){
        System.out.println("/login被调用 thread id is : " + Thread.currentThread().getName());
        Callable<String> callable = new Callable<String>() {
            @Override
            public String call() throws Exception {
                //模拟长时间任务
                Thread.sleep(10000);
                ModelAndView mav = new ModelAndView("login/index");
                System.out.println("执行成功 thread id is : " + Thread.currentThread().getName());
                return "执行成功";
            }
        };
        return new WebAsyncTask<String>(callable);
    }
}
